home *** CD-ROM | disk | FTP | other *** search
- /*
- File: SpinCursor.c
-
- Contains: Cursor code.
-
- Written by: John Wang (and Think Reference people)
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <1> 11/15/94 JW New.
-
- To Do:
-
- */
-
- #ifdef THINK_C
- #define applec
- #endif
-
- #include "SpinCursor.h"
-
- static short gTickInterval; // number of ticks between a frame switch
- static long gLastTick; // tick count of last call to SpinCursor
- static acurHandle gFrameList; // our cursor list
-
- /* ------------------------------------------------------------------------- */
-
- /* Try to get the acur record and the cursor list for acurID, returning TRUE
- if everything goes as planned. */
-
- Boolean InitAnimatedCursors(short acurID, short interval)
- {
- short i=0;
- short cursID;
- Boolean noErrFlag = false;
-
- if ( (gFrameList = (acurHandle) GetResource('acur',acurID)) != nil ) {
- noErrFlag = true;
- while ( (i<(*gFrameList)->numberOfFrames) && noErrFlag ) {
- cursID = (short) HiWrd((long) (*gFrameList)->frame[i]);
- (*gFrameList)->frame[i] = GetCursor(cursID);
- if ( (*gFrameList)->frame[i] )
- i++; // get the next one
- else
- noErrFlag=false; // foo! we couldn't find the cursor
- }
- }
-
- if ( noErrFlag ) {
- // We have the cursors, now initialize the other fields
- gTickInterval = interval;
- gLastTick = TickCount();
- (*gFrameList)->whichFrame = 0;
- }
-
- return ( noErrFlag );
- }
-
- /* ------------------------------------------------------------------------- */
-
- /* Free up the storage used by the current animated cursor and all
- of its frames */
-
- void ReleaseAnimatedCursors()
- {
- short i;
-
- for ( i=0; i<(*gFrameList)->numberOfFrames; i++ )
- ReleaseResource((Handle) (*gFrameList)->frame[i]);
- ReleaseResource((Handle) gFrameList);
-
- SetCursor(&(qd.arrow));
- }
-
- /* ------------------------------------------------------------------------- */
-
- /* Display the next frame in the sequence, if it's time. If not, do nothing.
- This code should be pretty tight, but it might be possible to bum a few
- instructions; ideally it should be as fast as possible. I doubt it will
- be necessary to hand-hack it though.
-
- I chose this implementation over using a VBL task for the following reason:
- the whole point of using an animated cursor is to let the user know that
- your application is chugging away doing something. With this technique if
- the applications shoots off to never-never land, the cursor will probably
- stop spinning. A VBL task, on the other hand, would probably just sit and
- merrily go on spinning away, the user none the wiser. */
-
- void SpinCursor()
- {
- register long newTick;
-
- newTick = TickCount();
-
- // Is it time?
- if ( newTick < (gLastTick + gTickInterval) )
- return; // nope
-
- // Grab the frame, increment (and reset, if necessary) the count, and
- // display the new cursor
- SetCursor(*((*gFrameList)->frame[(*gFrameList)->whichFrame++]));
- if ( (*gFrameList)->whichFrame == (*gFrameList)->numberOfFrames )
- (*gFrameList)->whichFrame = 0;
- gLastTick = newTick;
- }